﻿@using System.Globalization
@using OrchardPo.Helpers
@using OrchardPo.ViewModels
@model CultureGroupDetailsViewModel
@{
    Layout.Title = T("{0} Localization", Model.Culture);
    Style.Require("jQueryUI_Orchard");
    Script.Require("jQueryUI_Dialog");
    using(Script.Foot()) {
<script type="text/javascript">
    jQuery(function ($) {
        var editPane = $("#editPane");
        function saveEditPane() {
            var updatedValue = $("#updatedValue").val();
            var id = editPane.data("translationid");
            $.post("@Url.Action("Update", "Localization")",
                {
                    id: id,
                    culture: '@Model.Culture',
                    value: updatedValue,
                    __RequestVerificationToken: $("#__requesttoken").val()
                },
                function(data) {
                    var li = editPane.data("li");
                    li.find(".originalString").css("color", "black");
                    li.find(".localString").text(data);
                    editPane.dialog("close");
                    li.find("button").focus();
                });
        }
        editPane.dialog({
            autoOpen: false,
            height: 530,
            width: 780,
            modal: true,
            resizable: false,
            buttons: {
                Save: saveEditPane,
                Cancel: function () {
                    editPane.dialog("close");
                }
            }
        });
        $("#updatedValue").keypress(function(e) {
            if (e.ctrlKey === true && (e.which == 10 || e.which == 13)) {
                saveEditPane();
            }
        });
        $(".editButton").click(function () {
            var li = $(this).closest("li");
            $("#originalValue").val(li.find(".originalString").text());
            $("#updatedValue").val(li.find(".localString").text());
            $("#editPaneContext").text(li.find(".translationContext").text());
            editPane.data({
                translationid: li.data("translationid"),
                li: li
            }).dialog("open");
        });
        var confirmDelete = $("#confirmDelete");
        confirmDelete.dialog({
            autoOpen: false,
            resizable: false,
            width: 500,
			height:270,
			modal: true,
			buttons: {
				Delete: function() {
                    var id = confirmDelete.data("translationid");
                    $.post("@Url.Action("Remove", "Localization")",
                        {
                            id: id,
                            culture: "@Model.Culture",
                            __RequestVerificationToken: $("#__requesttoken").val()
                        },
                        function() {
                            var li = confirmDelete.data("li");
                            li.remove();
                            confirmDelete.dialog("close");
                        });
				},
				Cancel: function() {
					confirmDelete.dialog("close");
				}
			}
        });
        $(".deleteButton").click(function () {
            var li = $(this).closest("li");
            confirmDelete.data({
                translationid: li.data("translationid"),
                li: li
            }).dialog("open");
        });
    });
</script>
    }
}
<ol id="contentFull" style="min-height:500px">
<li class="moduleContentFull">
  <div class="content">
    @Html.ActionLink(T("Download the PO files").ToString(), "Download", new {culture = Model.Culture}) -
    @Html.ActionLink(T("Back to the index").ToString(), "Index")
    <h2>@(Model.Culture + " - " + new CultureInfo(Model.Culture).DisplayName)</h2>
    <ul id="translationGroups">
    @foreach (var group in Model.Groups) {
        var current = Model.CurrentGroupPath.Equals(group.Path, StringComparison.OrdinalIgnoreCase);
        <li@(current ? " class=\"selected\"" : "")>
            @if(current) {
                @(LocalizationHelpers.GetPoFileName(group.Path))
            }
            else {
               <a href="@group.Url">@(LocalizationHelpers.GetPoFileName(group.Path))</a>
            }
        (<span class="translationCount"
               title="@T.Plural("{0} string", "{0} strings", group.TotalCount)">
               @(group.TotalCount)
         </span>
         @if (!group.IsComplete) {
            <text>&nbsp;/&nbsp;</text>
            <span class="translationMissingCount"
                  title="@T.Plural("{0} missing translation", "{0} missing translations", group.MissingCount)">
                @(group.MissingCount)
            </span>
            <text>&nbsp;/&nbsp;</text>
            <span class="translationObsoleteCount"
                  title="@T.Plural("{0} obsolete translation", "{0} obsolete translations", group.ObsoleteCount)">
                @(group.ObsoleteCount)
            </span>
        })
        </li>
        }
    </ul>

    @if (!String.IsNullOrEmpty(Model.CurrentGroupPath)) {
    <div id="translations">
        <h3>@(String.Format(Model.CurrentGroupPath, Model.Culture))</h3>
        <ul>@foreach (var translation in Model.CurrentGroupTranslations) {
            <li data-translationid="@translation.Id">
                <b class="originalString" @(LocalizationHelpers.BuildStyleAttribute(translation))>@translation.OriginalString</b>
                (<span class="translationContext">@translation.Context</span>)
                <p class="localString">@translation.LocalString</p>
                @if (Model.CanTranslate) {
                <div class="actions">
                    <button class="editButton linkButton">@T("Edit")</button>
                    @if (!translation.ExistsInEnglish) {
                    <text>| </text><button class="deleteButton linkButton">@T("Delete")</button>
                    }
                </div>
                }
                <hr />
            </li>
            }
        </ul>
    </div>
    }
  </div>
</li>
</ol>
<div style="display:none" id="editPane" title="Edit">
	<input id="__requesttoken" type="hidden" value="@Html.AntiForgeryTokenValueOrchard()" />
    <div id="editPaneContext"></div>
    <br />
    <label for="originalValue">@T("Original string:")</label>
    <textarea id="originalValue" class="translationField" rows="6" cols="75" disabled="disabled"></textarea>
    <label for="updatedValue">@T("Translation:")</label>
    <textarea id="updatedValue" class="translationField" rows="6" cols="75"></textarea>
</div>
<div id="confirmDelete" style="display:none" title="Delete the translation?">
	<p>
        <span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>
        @T("This translation is probably obsolete as the default language version does not exist. It will likely never be displayed by the application and can be deleted. The translation will be permanently deleted and cannot be recovered. Are you sure?")
    </p>
</div>
<div class="clearLayout">
</div>